home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 April / EnigmA AMIGA RUN 06 (1996)(G.R. Edizioni)(IT)[!][issue 1996-04][Skylink CD V].iso / earcd / utilgfx / amipeg05.lha / aMiPEG05 / motionvector.c < prev    next >
C/C++ Source or Header  |  1994-04-22  |  5KB  |  174 lines

  1. /*
  2.  *  This file handles computation of the forward/backward motion vectors.
  3.  */
  4.  
  5. #include "video.h"
  6. #include "proto.h"
  7. #include "util.h"
  8.  
  9.  
  10. /*
  11.  *--------------------------------------------------------------
  12.  *
  13.  * ComputeVector --
  14.  *
  15.  *    Computes motion vector given parameters previously parsed
  16.  *      and reconstructed.
  17.  *
  18.  * Results:
  19.  *      Reconstructed motion vector info is put into recon_* parameters
  20.  *      passed to this function. Also updated previous motion vector
  21.  *      information.
  22.  *
  23.  * Side effects:
  24.  *      None.
  25.  *
  26.  *--------------------------------------------------------------
  27.  */
  28.  
  29. #define ComputeVector(recon_right_ptr, recon_down_ptr, recon_right_prev, recon_down_prev, f, full_pel_vector, motion_h_code, motion_v_code, motion_h_r, motion_v_r)                \
  30.                                     \
  31. {                                    \
  32.   int comp_h_r, comp_v_r;                        \
  33.   int right_little, right_big, down_little, down_big;            \
  34.   int max, min, new_vector;                        \
  35.                                     \
  36.   /* The following procedure for the reconstruction of motion vectors     \
  37.      is a direct and simple implementation of the instructions given    \
  38.      in the mpeg December 1991 standard draft.                 \
  39.   */                                    \
  40.                                     \
  41.   if (f == 1 || motion_h_code == 0)                    \
  42.     comp_h_r = 0;                            \
  43.   else                                     \
  44.     comp_h_r = f - 1 - motion_h_r;                    \
  45.                                     \
  46.   if (f == 1 || motion_v_code == 0)                    \
  47.     comp_v_r = 0;                            \
  48.   else                                     \
  49.     comp_v_r = f - 1 - motion_v_r;                    \
  50.                                     \
  51.   right_little = motion_h_code * f;                    \
  52.   if (right_little == 0)                        \
  53.     right_big = 0;                            \
  54.   else {                                \
  55.     if (right_little > 0) {                        \
  56.       right_little = right_little - comp_h_r;                \
  57.       right_big = right_little - (f<<5);                \
  58.     }                                    \
  59.     else {                                \
  60.       right_little = right_little + comp_h_r;                \
  61.       right_big = right_little + (f<<5);                \
  62.     }                                    \
  63.   }                                    \
  64.                                     \
  65.   down_little = motion_v_code * f;                    \
  66.   if (down_little == 0)                            \
  67.     down_big = 0;                            \
  68.   else {                                \
  69.     if (down_little > 0) {                        \
  70.       down_little = down_little - comp_v_r;                \
  71.       down_big = down_little - (f<<5);                    \
  72.     }                                    \
  73.     else {                                \
  74.       down_little = down_little + comp_v_r;                \
  75.       down_big = down_little + (f<<5);                    \
  76.     }                                    \
  77.   }                                    \
  78.                                       \
  79.   max = (f << 4) - 1;                            \
  80.   min = -(f << 4);                            \
  81.                                     \
  82.   new_vector = recon_right_prev + right_little;                \
  83.                                     \
  84.   if (new_vector <= max && new_vector >= min)                \
  85.     *recon_right_ptr = recon_right_prev + right_little;            \
  86.                       /* just new_vector */                \
  87.   else                                    \
  88.     *recon_right_ptr = recon_right_prev + right_big;            \
  89.   recon_right_prev = *recon_right_ptr;                    \
  90.   if (full_pel_vector)                            \
  91.     *recon_right_ptr = *recon_right_ptr << 1;                \
  92.                                     \
  93.   new_vector = recon_down_prev + down_little;                \
  94.   if (new_vector <= max && new_vector >= min)                \
  95.     *recon_down_ptr = recon_down_prev + down_little;            \
  96.                       /* just new_vector */                \
  97.   else                                    \
  98.     *recon_down_ptr = recon_down_prev + down_big;            \
  99.   recon_down_prev = *recon_down_ptr;                    \
  100.   if (full_pel_vector)                            \
  101.     *recon_down_ptr = *recon_down_ptr << 1;                \
  102. }
  103.  
  104. /*
  105.  *--------------------------------------------------------------
  106.  *
  107.  * ComputeForwVector --
  108.  *
  109.  *    Computes forward motion vector by calling ComputeVector
  110.  *      with appropriate parameters.
  111.  *
  112.  * Results:
  113.  *    Reconstructed motion vector placed in recon_right_for_ptr and
  114.  *      recon_down_for_ptr.
  115.  *
  116.  * Side effects:
  117.  *      None.
  118.  *
  119.  *--------------------------------------------------------------
  120.  */
  121.  
  122. void ComputeForwVector(int *recon_right_for_ptr, int *recon_down_for_ptr)
  123. {
  124.  
  125.   Pict *picture;
  126.   Macroblock *mblock;
  127.  
  128.   picture = &(curVidStream->picture);
  129.   mblock = &(curVidStream->mblock);
  130.  
  131.   ComputeVector(recon_right_for_ptr, recon_down_for_ptr,
  132.         mblock->recon_right_for_prev, 
  133.         mblock->recon_down_for_prev,
  134.         picture->forw_f, picture->full_pel_forw_vector,
  135.         mblock->motion_h_forw_code, mblock->motion_v_forw_code,
  136.         mblock->motion_h_forw_r, mblock->motion_v_forw_r); 
  137. }
  138.  
  139.  
  140. /*
  141.  *--------------------------------------------------------------
  142.  *
  143.  * ComputeBackVector --
  144.  *
  145.  *    Computes backward motion vector by calling ComputeVector
  146.  *      with appropriate parameters.
  147.  *
  148.  * Results:
  149.  *    Reconstructed motion vector placed in recon_right_back_ptr and
  150.  *      recon_down_back_ptr.
  151.  *
  152.  * Side effects:
  153.  *      None.
  154.  *
  155.  *--------------------------------------------------------------
  156.  */
  157.  
  158. void ComputeBackVector(int *recon_right_back_ptr, int *recon_down_back_ptr)
  159. {
  160.   Pict *picture;
  161.   Macroblock *mblock;
  162.  
  163.   picture = &(curVidStream->picture);
  164.   mblock = &(curVidStream->mblock);
  165.  
  166.   ComputeVector(recon_right_back_ptr, recon_down_back_ptr,
  167.         mblock->recon_right_back_prev, 
  168.         mblock->recon_down_back_prev,
  169.         picture->back_f, picture->full_pel_back_vector,
  170.         mblock->motion_h_back_code, mblock->motion_v_back_code,
  171.         mblock->motion_h_back_r, mblock->motion_v_back_r); 
  172.  
  173. }
  174.